// wdl_esfroom/pages/index/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: [],
    channel: [],
    hotHouse: [],
    hotzhu: [],
    newhouse: [],
    siteroot: '',
    storage: {},
    adinfo: [],
    diymenu: [{
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon_02.jpg',
        name: '热门楼盘'
      },
      {
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon_04.jpg',
        name: '商业热售'
      } ,{
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon_06.jpg',
        name: '清盘优惠'
      }, {
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon_08.jpg',
        name: '商业招租'
      } ,{
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon_10.jpg',
        name: '预算广播'
      } ,{
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon2_02.jpg',
        name: '服务预约'
      }, {
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon2_04.jpg',
        name: '企业招聘'
      }, {
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon2_06.jpg',
        name: '楼盘社区'
      }, {
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon2_08.jpg',
        name: '领取优惠'
      }, {
        pathurl: '',
        iconpic: '/wdl_weihouse/diy/icon2_10.jpg',
        name: '会员商城'
      } 
    ]

  },
  /**
   * 获取diy版块
   */
  onblockdata: function(){
    var self = this;
    app.util.request({
      'url': 'entry/wxapp/diy',
      'cachetime': '0',
      showLoading: false,
      data: { },
      success(res) {
        self.setData({ jack: res.data.data}) ;
      }
    });
  },
  /**获取配置参数 */
  onPageInitData: function() {
    var self = this;
    app.util.request({
      'url': 'entry/wxapp/enset',
      'cachetime': '0',
      showLoading: false,
      data: {
        placeids: '1,2,4,5,6,11'
      },
      success(res) {
        var d = res.data.data;

        var storage = self.storage;
        var banner = [];
        /**加载 幻灯片        
        if (!app.kbtools.isnull(d.banner)) {
          for (var k in d.banner.image) {
            if (!app.kbtools.isnull(d.banner.image[k])) {
              banner.push({ link: d.banner.link[k], url: d.banner.image[k] })
            }
          }
        }*/
        /**没有配置轮播图 调用logo 
        if (banner.length == 0) {
          banner: [
            { link: '', url: storage.logo },
            { link: '', url: storage.banner }
          ];
        }*/
        var index_search = 0;
        var index_tongji = 0;
        var index_slide_show = 1;
        if (!app.kbtools.isnull(d.confmenu.index_searchbar)) {
          index_search = 1;
        }
        if (!app.kbtools.isnull(d.confmenu.index_tongji)) {
          index_tongji = 1;
        }
        if (!app.kbtools.isnull(d.confmenu.indexslide)) {
          index_slide_show = 0;
        }
        /**处理顶部导航条 */
        var index_searchbar_txt = '新房';
        var index_search_place = '您想把家住哪？';
        var index_searchbar_jump = 1;
        var index_searchbar_jump_url = '../newshop/search';
        if (!app.kbtools.isnull(d.confmenu.index_searchbar_txt)) {
          index_searchbar_txt = d.confmenu.index_searchbar_txt;
        }
        if (!app.kbtools.isnull(d.confmenu.index_search_place)) {
          index_search_place = d.confmenu.index_search_place;
        }
        if (!app.kbtools.isnull(d.confmenu.index_searchbar_jump)) {
          index_searchbar_jump = d.confmenu.index_searchbar_jump;
          if (index_searchbar_jump == 1) {
            index_searchbar_jump_url = '../newshop/search';
          } else if (index_searchbar_jump == 2) {
            index_searchbar_jump_url = '../house/search';
          } else if (index_searchbar_jump == 3) {
            index_searchbar_jump_url = '../house/zhu';
          } else if (index_searchbar_jump == 4) {
            index_searchbar_jump_url = '../house/sp?rent=0&zhutype=2';
          } else if (index_searchbar_jump == 5) {
            index_searchbar_jump_url = '../house/sp?rent=2&zhutype=2';
          } else if (index_searchbar_jump == 6) {
            index_searchbar_jump_url = '../house/syi?rent=0&zhutype=3';
          } else if (index_searchbar_jump == 7) {
            index_searchbar_jump_url = '../house/xie?rent=2&zhutype=1';
          } else if (index_searchbar_jump == 8) {
            index_searchbar_jump_url = '../house/xie?rent=0&zhutype=1';
          } else {
            index_searchbar_jump_url = '../newshop/search';
          }
        }
        /*
         { name: '出售', url: '../house/search?rent=0&zhutype=0', opentype: 'redirect' },
          { name: '租房', url: '../house/zhu?rent=2&zhutype=2', opentype: 'redirect' },
          { name: '写字楼出租', url: '../house/xie?rent=2&zhutype=1', opentype: 'redirect' },
          { name: '写字楼出售', url: '../house/xie?rent=0&zhutype=1', opentype: 'redirect' },
          { name: '商铺出租', url: '../house/sp?rent=2&zhutype=2', opentype: 'redirect' },
          { name: '商铺出售', url: '../house/sp?rent=0&zhutype=2', opentype: 'redirect' },
          { name: '生意转让', url: '../house/syi?rent=0&zhutype=3', opentype: 'redirect' }
          */
        /**处理顶部导航条 end */
        self.setData({
          banner: banner,
          index_search: index_search,
          index_tongji: index_tongji,
          index_slide_show: index_slide_show,
          pagedata: d,
          index_searchbar_txt: index_searchbar_txt,
          index_search_place: index_search_place,
          index_searchbar_jump: index_searchbar_jump,
          index_searchbar_jump_url: index_searchbar_jump_url
        });
        /**==== */
      }
    });
    /**导航菜单 */
    app.util.request({
      'url': 'entry/wxapp/enset',
      'cachetime': '0',
      showLoading: false,
      data: {
        'op': 'navmenu'
      },
      success(res) {
        self.setData({
          navmenu: res.data.data
        })
      }
    });
    /**广告数据 */
    app.kbtools.siteAdvancise(app, self);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const self = this;
    /**执行站点任务计划 */
    app.util.request({
      'url': 'entry/wxapp/runtask',
      'cachetime': '0',
      success(res) {}
    });
    /**获取参数SettingData */
    app.kbtools.get_settingdata(self, function(res) {
      wx.setNavigationBarTitle({
        title: res.data.shopname,
      })
      self.setData({
        storage: res.data
      })
    });

    /**获取配置参数 */
    self.onPageInitData();
    self.onblockdata();

    /**判断是否从推广进入 如果是就跳转到我的资料*/
    if (!app.kbtools.isnull(options.scene)) {
      wx.navigateTo({
        url: '/wdl_weihouse/pages/share/agent?scence=' + options.scene,
      })
    }

    /**新房5条 
    app.util.request({
      'url': 'entry/wxapp/newhouseByfield',
      'cachetime': '30',
      showLoading: false,
      data: {
        'limit': 5
      },
      success(res) {
        self.setData({
          newhouse: res.data.data
        })
      }
    });
*/
    /**置顶二手房信息20条
    app.util.request({
      'url': 'entry/wxapp/limithouse',
      'cachetime': '10',
      showLoading: false,
      data: {
        'fkey[rent_type]': 0,
        'limit': 20,
        'fkey[isjingpin]': 1,
        'fkey[zhutype]': 0
      },
      success(res) {
        self.setData({
          hotHouse: res.data.data
        })
      }
    }); */
    /**置顶租房信息20条 
    app.util.request({
      'url': 'entry/wxapp/limithouse',
      'cachetime': '30',
      showLoading: false,
      data: {
        'fkey[rent_type]': 2,
        'limit': 20,
        'fkey[isjingpin]': 1,
        'fkey[zhutype]': 0
      },
      success(res) {
        self.setData({
          hotzhu: res.data.data
        })
      }
    });*/
    /**判断是否分享入口 */
    if (!app.kbtools.isnull(options.share)) {
      wx.navigateTo({
        url: '/wdl_weihouse/pages/newshop/index?id=' + options.id,
      });
      return;
    }
  },
  /**打开外联 
  openadlink: function(e){
      console.log(e);
      var data = e.currentTarget.dataset;
      if( app.kbtools.isnull(data.appid)){
        wx.navigateTo({
          url: data.url,
        })
      }else{
        wx.navigateBackMiniProgram({
          appId: data.appid,
          path: data.url
        })
      }
  },*/
  /**签到  */
  bindtap_qiandao: function(e) {
    /**需要登录 */
    app.checkAuthorLogin(this,
      '/wdl_weihouse/pages/index/welcome',
      function() {
        /**继续操作 */
        app.util.request({
          'url': 'entry/wxapp/qiandao',
          'cachetime': '0',
          showLoading: false,
          data: {},
          success(res) {
            wx.showModal({
              title: '签到提示',
              content: res.data.data,
              showCancel: false
            })
          }
        });
      }
    );

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // 页面渲染完成
    const self = this;
    /**登录 
    app.util.getUserInfo(function (response) {} ) ;*/
    /**设置底部导航 */
    // app.setbottom_bar(this);
    /**设置网址 */
    self.setData({
      siteroot: app.kbtools.url_to_host(app.siteInfo.siteroot)
    })
    /**设置tabbar */
    wx.setTabBarItem({
      index: 4,
      text: 'text',
      iconPath: '/path/to/iconPath',
      selectedIconPath: '/path/to/selectedIconPath'
    })

  },

  /**处理全局事件统一处理 */
  onDefRedirect: function(e) {
    app.kbtools.defRedirect(this, e);
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.onPageInitData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    const self = this;
    return {
      title: self.data.storage.shopname,
      desc: '',
      path: '/wdl_weihouse/pages/index/welcome'
    }
  }
})